<link rel="stylesheet" href="../../../static/comment/css/comment.css" />
<script src="../../../static/layer/layer.js" type="text/javascript" charset="utf-8"></script>
<div id="comment_main_box" class="row">
	<div class="col-md-7 col-md-offset-1">
		{include file="collection/collection"} {include file="score/score"}
		<div id="write_box">
			<textarea id="com_content" rows="2" placeholder="来说两句吧！" class="form-control"></textarea>
			<a id="add_dy_com" class="btn btn-primary">评论</a>
		</div>
		<div id="show_box">
			<p id="show_box_title">评论区<small>（已有{$list->total()}条评论）</small></p>
			{volist name="list" id="comment"}
			<hr />
			<div class="comment_box">
				<div class="comment_photo">
					<img src="__PUBLIC__/static/user/headimg/{$comment.sender.user_photo}"/>
				</div>
				<div class="comment_info">
					<div class="detail_info">
						<a name={$comment.sender_id} class="detail_name" href="">{$comment.sender.user_name}</a>
						<span class="detail_time">{$comment.time}</span>
					</div>
				</div>
				<div class="comment_content">
					<p>{$comment.content}</p>
					<span class="reply_com_btn"><small>回复</small></span>
				</div>
			</div>
			{/volist} {$list->render()}
		</div>
	</div>
</div>
<div id="reply_box" style="display: none;">
	<!--<span style="display: none;" id="story_id">receiver_id</span>-->
	<textarea id="reply_com_content" rows="4" placeholder="来说两句吧！" class="form-control"></textarea>
	<a id="reply_dy_com" style="float: right;margin-top: 10px;" class="btn btn-primary">回复</a>
</div>
<script type="text/javascript">
	$(function() {
		//页面初始化操作
		$(document).ready(function() {
			var score_content = $("#score_content");
			var score_box = $("#score_box");
			//判断当前用户是否已经打分该动态
			$.ajax({
				type: "get",
				url: "../../index/Score/checkscore",
				async: true,
				success: function(data) {
					if(data.statue == "1") {
						//当前用户已经打分该动态
						score_content.eq(0).val(data.score);
						score_box.css("display", "none");
					} else {
						//当前用户没有打分该动态

					}
				},
				error: function() {
					alert("服务器出错了")
				}
			});
			//判断当前用户是否已经收藏该动态
			$.ajax({
				type: "get",
				url: "../../index/Collection/checkcollect",
				async: true,
				success: function(data) {
					if(data == "1") {
						//当前用户已经收藏该动态
						$("#un_collect").css("display", "none");
						$("#collect").css("display", "block");
					}
				},
				error: function() {
					alert("服务器出错了")
				}
			});
		})

		//点击评论按钮新增评论
		$("#add_dy_com").on("click", function() {
			var content = $("#com_content").val();
			if(content==""){
				alert("评论不能为空");
				return false;
			}
			$.ajax({
				type: "post",
				url: "../../index/Comment/addcomment",
				async: true,
				data: {
					'content': content,
				},
				success: function(data) {
					if(data == "0") {
						//页面添加新的评论
						alert("添加评论成功");
						window.location.reload(true);
					} else {
						alert("添加评论失败!")
					}
				},
				error: function() {
					alert("服务器出错了")
				}
			});

		})

		//点击回复按钮弹出回复框
		$("#show_box").delegate(".reply_com_btn", "click", function() {
//			$("#story_id").text($(this).parents(".comment_box").find(".detail_name").attr("name"));
			var receiver_nickname = "@" + $(this).parents(".comment_box").find(".detail_name").text();
			$("#reply_box").find("textarea").eq(0).text(receiver_nickname);
			layer.open({
				type: 1,
				title: '回复评论',
				maxmin: true,
				anim: 2,
				offset: '320px',
				//shadeClose: true, //点击遮罩关闭层
				area: ['480px', '200px'],
				content: $("#reply_box"),
				success: function(layero, index) {
					console.log(layero, index);
				}
			});
//			$("#reply_box").css("display","none");
		})

		//点击回复按钮添加回复信息
		$("#reply_dy_com").on("click", function() {
			var content = $("#reply_com_content").val();
			var receiver_id = $("#story_id").text();
			$.ajax({
				type: "post",
				url: "../../index/Comment/replycomment",
				async: true,
				data: {
					'content': content,
					'receiver_id': receiver_id
				},
				success: function(data) {
					if(data == "0") {
						//页面添加新的评论
						alert("回复评论成功");
						window.location.reload(true);
					} else {
						alert("回复评论失败!");
					}
				},
				error: function() {
					alert("服务器出错了")
				}
			});
		})

		//点击打分按钮添加打分记录
		$("#score_btn").on("click", function() {
			var score = $("#score_content").val();
			//对于用户打分输入进行基本的检测
			if(!(score > 0 && score <= 100)) {
				$("#score_content").val("");
				alert("请输入一个0-100之间的评分！");
				return false;
			} else if($("#score_btn").eq(0).attr("disabled")) {
				alert("已打分");
				return false;
			}

			$.ajax({
				type: "post",
				url: "../../index/score/score",
				async: true,
				data: {
					'score': score
				},
				success: function(data) {
					if(data == "0") {
						alert("打分成功!");
						$("#score_btn").eq(0).css("display", "none");
//						window.location.reload(true);
					} else {
						alert("打分失败!");
					}
				},
				error: function() {
					alert("服务器出错了")
				}
			});
		})

		//点击收藏按钮收藏该动态
		$("#collect_btn").on("click", function() {
			$.ajax({
				type: "post",
				url: "../../index/Collection/collect",
				async: true,
				success: function(data) {
					if(data == "0") {
						$("#un_collect").css("display", "none");
						$("#collect").css("display", "block");
					} else {
						alert("收藏失败!");
					}
				},
				error: function() {
					alert("服务器出错了")
				}
			});
		})

		//点击动态取消收藏该动态
		$("#discollect_btn").on("click", function() {
			$.ajax({
				type: "post",
				url: "../../index/Collection/cancelcollect",
				async: true,
				success: function(data) {
					if(data == "0") {
						$("#un_collect").css("display", "block");
						$("#collect").css("display", "none");
					} else {
						alert("取消收藏失败!");
					}
				},
				error: function() {
					alert("服务器出错了")
				}
			});

		})
	})
</script>
{include file="footer"/}